#include <stdio.h>

typedef struct Shape
{
    void (*draw)(void* self);
    void (*resize)(void* self, float factor);
} Shape;

typedef struct Circle
{
    Shape methods;
    float radius;
} Circle;

void circle_draw(void* self)
{
    Circle* c = (Circle*) self;
    printf("Drawing circle with radius %.2f\n", c->radius);
}

void circle_resize(void* self, float factor)
{
    Circle* c = (Circle*)self;
    c->radius *= factor;
}

/**
 * 函数指针表实现多态性
*/
int main(int argc, char const *argv[])
{
    Circle circle = {
        .methods = {circle_draw, circle_resize},
        .radius = 5.0
    };

    Shape* shape = (Shape*) &circle;
    shape->draw(shape);
    shape->resize(shape, 1.5);
    shape->draw(shape);

    return 0;
}